#include <iostream>
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10

using namespace std;

typedef struct {
    string num;
    string name;
    int english;
    int c_language;
    int data_structure;
}StuType;

typedef StuType ElemType;

typedef struct {
    ElemType *elem;
    int length;
    int listsize;
}SqList;

bool InitList_Sq(SqList &L)
{
    L.elem = (ElemType *)malloc(LIST_INIT_SIZE * sizeof(ElemType));
    if (!L.elem) exit(EOVERFLOW);
    L.length = 0;
    L.listsize = LIST_INIT_SIZE;

    return true;
}

bool ListInsert_Sq(SqList &L, int i, ElemType e)
{
    if (i < 1 || i > L.length + 1) return false;
    if (L.length >= L.listsize)
    {
        ElemType *newbase = (ElemType *)realloc(L.elem, (L.listsize + LISTINCREMENT) * sizeof(ElemType));
        if (!newbase) exit(EOVERFLOW);
        L.elem = newbase;
        L.listsize += LISTINCREMENT;
    }
    ElemType *q = &(L.elem[i - 1]);
    for (ElemType *p = &(L.elem[L.length - 1]); p >= q; --p) *(p + 1) = *p;
    *q = e;
    L.length++;

    return true;
}

bool ListDelete_Sq(SqList &L, int i, ElemType &e)
{
    if ((i < 1) || (i > L.length)) return false;
    ElemType *p = &(L.elem[i- 1]);
    e = *p;
    ElemType *q = L.elem + L.length - 1;
    for (p++; p <= q; p++) *(p - 1) = *p;
    L.length--;

    return true;
}

// 其实可以用运算符重载处理更好
bool Compare(ElemType x, ElemType y)
{
    if ((x.num == y.num) && (x.name == y.name) && (x.english == y.english) && (x.c_language == y.c_language) && (x.data_structure == y.data_structure))
        return true;
    else
        return false;
}

int LocateElem_Sq(SqList L, ElemType e, bool (* compare)(ElemType, ElemType))
{
    int i = 1;
    ElemType *p = L.elem;
    while (i <= L.length && !(* compare)(*p++, e)) i++;
    if (i <= L.length) return i;
    else return 0;
}

void MergeList_Sq(SqList La, SqList Lb, SqList &Lc)
{
    ElemType *pa = La.elem, *pb = Lb.elem;
    Lc.listsize = Lc.length = La.length + Lb.length;
    ElemType *pc = Lc.elem = (ElemType *)malloc(Lc.listsize * sizeof(ElemType));
    if (!Lc.elem) exit(EOVERFLOW);
    ElemType *pa_last = La.elem + La.length - 1;
    ElemType *pb_last = Lb.elem + Lb.length - 1;
    while (pa <= pa_last && pb <= pb_last)
    {
        // 合并数据
        // if (...) *pc++ = *pa++;
        // else *pc++ = *pb++;
    }
    while (pa <= pa_last) *pc++ = *pa++;
    while (pb <= pb_last) *pc++ = *pb++;
}

int main() {


    return 0;
}